<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="设备种类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['deviceType']" placeholder="请输入设备种类"></a-input>
        </a-form-item>
        <a-form-item label="设备名称和型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['deviceNameModel']" placeholder="请输入设备名称和型号"></a-input>
        </a-form-item>
        <a-form-item label="是否保留" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['saveOrDiscard']" placeholder="请输入是否保留"></a-input>
        </a-form-item>
        <a-form-item label="类别型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['typeNumber']" placeholder="请输入类别型号"></a-input>
        </a-form-item>
        <a-form-item label="卡片型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['card']" placeholder="请输入卡片型号"></a-input>
        </a-form-item>
        <a-form-item label="资产编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['assetNumber']" placeholder="请输入资产编号"></a-input>
        </a-form-item>
        <a-form-item label="资产名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['assetName']" placeholder="请输入资产名称"></a-input>
        </a-form-item>
        <a-form-item label="使用部门" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['useDepart']" placeholder="请输入使用部门"></a-input>
        </a-form-item>
        <a-form-item label="原值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['oldValue']" placeholder="请输入原值"></a-input>
        </a-form-item>
        <a-form-item label="净值" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['netValue']" placeholder="请输入净值"></a-input>
        </a-form-item>
        <a-form-item label="累计折旧" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['totalDepreciation']" placeholder="请输入累计折旧"></a-input>
        </a-form-item>
        <a-form-item label="规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['model']" placeholder="请输入规格型号"></a-input>
        </a-form-item>
        <a-form-item label="类别名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['typeName']" placeholder="请输入类别名称"></a-input>
        </a-form-item>
        <a-form-item label="开始使用时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择开始使用时间" v-decorator="['startTime']" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="累计使用年月" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['useMonth']" placeholder="请输入累计使用年月" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="累计计提年月" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['jitiMonth']" placeholder="请输入累计计提年月"></a-input>
        </a-form-item>
        <a-form-item label="折旧科目" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['depreciation']" placeholder="请输入折旧科目"></a-input>
        </a-form-item>
        <a-form-item label="原值万元" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['oldValueW']" placeholder="请输入原值万元"></a-input>
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['remark']" placeholder="请输入备注"></a-input>
        </a-form-item>
        <a-form-item label="额定功率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['power']" placeholder="请输入额定功率"></a-input>
        </a-form-item>
        <a-form-item label="能耗比" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['powerConsumptionRatio']" placeholder="请输入能耗比"></a-input>
        </a-form-item>
        <a-form-item label="物料1名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['material1Name']" placeholder="请输入物料1名称"></a-input>
        </a-form-item>
        <a-form-item label="物料1编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['material1Code']" placeholder="请输入物料1编码"></a-input>
        </a-form-item>
        <a-form-item label="物料1月使用量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['material1MonthUse']" placeholder="请输入物料1月使用量"></a-input>
        </a-form-item>
        <a-form-item label="物料1单价" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['material1Price']" placeholder="请输入物料1单价"></a-input>
        </a-form-item>
        <a-form-item label="直接费率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['directRate']" placeholder="请输入直接费率" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="辅助费率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['indirectRate']" placeholder="请输入辅助费率" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="设备折旧费率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['depreciationRate']" placeholder="请输入设备折旧费率" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="机物料费率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['materialRate']" placeholder="请输入机物料费率" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="人工费率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['userRate']" placeholder="请输入人工费率" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="每小时设备成本" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['hourlyEquipmentCost']" placeholder="请输入每小时设备成本" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="每小时辅助成本" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['hourlyIndirectCost']" placeholder="请输入每小时辅助成本" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="每小时人工成本" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['hourlyLaborCost']" placeholder="请输入每小时人工成本" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="每小时总成本" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="['totalHourlyCost']" placeholder="请输入每小时总成本" style="width: 100%"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  


  export default {
    name: "DeviceInfoModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/deviceInfo/deviceInfo/add",
          edit: "/deviceInfo/deviceInfo/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'deviceType','deviceNameModel','saveOrDiscard','typeNumber','card','assetNumber','assetName','useDepart','oldValue','netValue','totalDepreciation','model','typeName','startTime','useMonth','jitiMonth','depreciation','oldValueW','remark','power','powerConsumptionRatio','material1Name','material1Code','material1MonthUse','material1Price','directRate','indirectRate','depreciationRate','materialRate','userRate','hourlyEquipmentCost','hourlyIndirectCost','hourlyLaborCost','totalHourlyCost'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'deviceType','deviceNameModel','saveOrDiscard','typeNumber','card','assetNumber','assetName','useDepart','oldValue','netValue','totalDepreciation','model','typeName','startTime','useMonth','jitiMonth','depreciation','oldValueW','remark','power','powerConsumptionRatio','material1Name','material1Code','material1MonthUse','material1Price','directRate','indirectRate','depreciationRate','materialRate','userRate','hourlyEquipmentCost','hourlyIndirectCost','hourlyLaborCost','totalHourlyCost'))
      },

      
    }
  }
</script>